import re
import requests


def cnvd(cms):
    r = requests.post(
        "https://www.cnvd.org.cn/flaw/list.htm?flag=true",
        headers={
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)"
                          " Chrome/91.0.4472.114 Safari/537.36",
            "Referer": "https://www.cnvd.org.cn/flaw/list.htm?flag=true",
            "Cookie": "__jsluid_s=a1e3ea55857b1ca2fb82cf355826a26c; __jsl_clearance_s=1624797867.579|0|PNnjse4BdwRSGtRm95"
                      "gfv1zV6OA%3D; JSESSIONID=1DCAEF7813DB70D0004517949C01AB45"
        },
        data={
            "keyword": cms,
            "condition": "1",
            "keywordFlag": "0",
            "cnvdId": "",
            "cnvdIdFlag": "0",
            "baseinfoBeanbeginTime": "",
            "baseinfoBeanendTime": "",
            "baseinfoBeanFlag": "0",
            "refenceInfo": "",
            "referenceScope": "-1",
            "manufacturerId": "-1",
            "categoryId": "-1",
            "editionId": "-1",
            "causeIdStr": "",
            "threadIdStr": "",
            "serverityIdStr": "",
            "positionIdStr": ""
        }
    )

    print(r.headers)
    print(r.text)

    data = re.findall(r'href="/flaw/show/(.*?)".*?title="(.*?)"', r.text, re.S)
    results = []

    for item in data:
        _cnvd, _title = item
        results.append(
            {"type": "Plain", "text": "{} {}\n".format(_cnvd, _title)}
        )
    return results


if __name__ == '__main__':
    cnvd("dedecms")